/*
ID:luongho3
LANG:JAVA
TASK:crypt1
 */
package usaco.training.chap1.sec3;

import java.io.File;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class crypt1 {

	static int N, count;
	static int[] nums;
	static int[] pos = new int[5];
	
	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(new File("crypt1.in"));
		PrintStream ps = new PrintStream(new File("crypt1.out"));
		System.setOut(ps);
		
		N = scanner.nextInt();
		nums = new int[N];
		for (int i=0;i<N;++i) {
			nums[i] = scanner.nextInt();
		}
		Arrays.sort(nums);
		count = 0;
		for (int i=0;i<N;++i) {
			pos[0] = nums[i];
			dfs(1);
		}
		System.out.println(count);
	}

	private static void dfs(int n) {
		if (n == 5) {
			int up = pos[0] * 100 + pos[1] * 10 + pos[2];
			int first = pos[4] * up;
			int second = pos[3] * up;
			int last = second * 10 + first;
			if (first >= 1000 || second >= 1000 || last >= 10000) {
				return;
			}
			else {
				if (!valid(first) || !valid(second) || !valid(last)) {
					return;
				}
				else {
					count++;
				}
			}
		}
		else {
			for (int i=0;i<N;++i) {
				pos[n] = nums[i];
				dfs(n+1);
			}
		}
	}

	private static boolean valid(int num) {
		while (num > 0) {
			int re = num % 10;
			num /= 10;
			if (Arrays.binarySearch(nums, re) < 0) {
				return false;
			}
		}
		return true;
	}

}
